Dedup overrides by name
authorAlex Crichton <alex@alexcrichton.com>
Fri, 29 Aug 2014 03:38:19 +0000 (20:38 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 2 Sep 2014 18:48:03 +0000 (11:48 -0700)
Overrides are only queried by name, and it's possible for multiple to show up,
and just pick the first one.

Closes #461

src/cargo/core/registry.rs
tests/test_cargo_compile_path_deps.rs

index 236f7e68c4076c9f24404e2536dc4cbb62b31b39..614d41077142bd6186c5a47473c1695c6e3bc913 100644 (file)
@@ -1,3 +1,5 @@
+use std::collections::HashSet;
+
 use core::{Source, SourceId, SourceMap, Summary, Dependency, PackageId, Package};
 use util::{CargoResult, ChainError, Config, human, profile};
 
@@ -100,11 +102,14 @@ impl<'a> PackageRegistry<'a> {
 
     fn query_overrides(&mut self, dep: &Dependency)
                        -> CargoResult<Vec<Summary>> {
+        let mut seen = HashSet::new();
         let mut ret = Vec::new();
         for s in self.overrides.iter() {
             let src = self.sources.get_mut(s).unwrap();
             let dep = Dependency::new_override(dep.get_name(), s);
-            ret.push_all_move(try!(src.query(&dep)));
+            ret.extend(try!(src.query(&dep)).move_iter().filter(|s| {
+                seen.insert(s.get_name().to_string())
+            }));
         }
         Ok(ret)
     }
index 4385826c8b8bc8b64a06f7ff3e21b022fad84be0..649a190099aebd35e32ef45afbb4171c3e463747 100644 (file)
@@ -569,3 +569,47 @@ test!(override_self {
     assert_that(p.cargo_process("build"), execs().with_status(0));
 
 })
+
+test!(override_path_dep {
+    let bar = project("bar")
+       .file("p1/Cargo.toml", r#"
+            [package]
+            name = "p1"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies.p2]
+            path = "../p2"
+       "#)
+       .file("p1/src/lib.rs", "")
+       .file("p2/Cargo.toml", r#"
+            [package]
+            name = "p2"
+            version = "0.5.0"
+            authors = []
+       "#)
+       .file("p2/src/lib.rs", "");
+
+    let p = project("foo")
+        .file(".cargo/config", format!(r#"
+            paths = ['{}', '{}']
+        "#, bar.root().join("p1").display(),
+            bar.root().join("p2").display()))
+        .file("Cargo.toml", format!(r#"
+            [package]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.p2]
+            path = '{}'
+
+        "#, bar.root().join("p2").display()))
+       .file("src/lib.rs", "");
+
+    bar.build();
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(0));
+
+})